package com.cositas.dulces.lp.promo2012.utils;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

public class MailSender {

	public static void sendEmail(String msgBody) throws UnsupportedEncodingException, MessagingException {
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);
		MimeMessage msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress("cositas.dulces.lp@gmail.com", "Cositas Dulces Lp"));
		msg.addRecipient(Message.RecipientType.TO, new InternetAddress("cositas.dulces.lp@gmail.com", "Cositas Dulces Lp"));
		if (msgBody.startsWith("Pedido")) {
			msg.setSubject("Nuevo pedido");
		} else {
			msg.setSubject("Nuevo presupuesto");
		}
		//msg.setText(msgBody);
		
        MimeBodyPart mimeBodyPart = new MimeBodyPart();
        mimeBodyPart.setContent(msgBody, "text/html;charset="+System.getProperty("file.encoding"));
        mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
        MimeMultipart mimeMultiPart = new MimeMultipart("related");        
        mimeMultiPart.addBodyPart(mimeBodyPart);
        msg.setContent(mimeMultiPart);
		
		Transport.send(msg);
	}
}
